//
//  EditBiography.m
//  HappyStore
//
//  Created by 李小辉 on 16/7/4.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "EditBiography.h"
#import "ExperienceVC.h"
#import "LookResume.h"
#import "AreasConcern.h"
#import "LabelVC.h"
#import "SingleSelectedDialog.h"
@interface EditBiography ()<selectedSingleRowDelegate>

@property (strong, nonatomic) NSDictionary *dicData; //数据源
@property (strong, nonatomic) NSArray *workExpAry;//工作经验
@property (strong, nonatomic) NSArray *moneyAry;
@property (strong, nonatomic) SingleSelectedDialog *workExpsingSelected;
@property (assign, nonatomic) BOOL booltig;
@end

@implementation EditBiography

- (NSArray *)workExpAry{
    if (!_workExpAry) {
        _workExpAry = @[@"1年以下",@"1～2年",@"2～3年",@"3年以上"];
    }
    return _workExpAry;
}
- (NSArray *)moneyAry{
    if (!_moneyAry) {
        _moneyAry = @[@"面议",@"1K以下",@"1K~3K",@"3K~5K",@"5K~7K",
                      @"7K~9K",@"10K~15K",@"15K~30K",@"30K以上"];
    }
    return _moneyAry;
}
- (NSDictionary *)dicData{
    if (!_dicData) {
        _dicData = [[NSDictionary alloc] init];
    }
    return _dicData;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = NO;
    navBarHairlineImageView.alpha = 0.5f;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = YES;

}
- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"编辑简历";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithTitle:@"下一步" style:UIBarButtonItemStylePlain target:self action:@selector(btnClickRight)];
    rightBar.tintColor = RGB(45, 45, 45);
    self.navigationItem.rightBarButtonItem = rightBar;
    //取消显示后退键文字
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleDone target:nil action:nil];
    self.navigationItem.backBarButtonItem = barButtonItem;
    // 设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    //加载数据
    [self startNetWork];
    //去掉多余的表格线
    [self setExtraCellLineHidden:self.tableView];
    //监听教育／职业经验变化
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notiExperienceExp:) name:@"experienceVCExp" object:nil];
    //监听行业方向
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveIndustry:) name:@"AreasConcernStr" object:nil];
    //监听技能标签
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveLabel:) name:@"biaoqian" object:nil];
    
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
}
//监听技能标签
- (void)receiveLabel:(NSNotification *)noti{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    NSArray *labelAry = dic[@"biaoqian"];
    NSString *string = @"";
    for (NSString *str in labelAry) {
        string = [string stringByAppendingString:[NSString stringWithFormat:@"%@,",str]];
    }
    if (string.length != 0) {
        string = [string substringWithRange:NSMakeRange(0, string.length - 1)];
    }else {
        string = @"";
    }

    [self updateResume:@"技能标签" tigString:string];
}
//监听行业方向
- (void)receiveIndustry:(NSNotification *)noti{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    [self updateResume:@"行业方向" tigString:dic[@"string"]];
    
}
//选择期望薪资
- (void)clickMoney{
    self.booltig = YES;
    self.workExpsingSelected = [SingleSelectedDialog sharedSelectedAddress];
    self.workExpsingSelected.delegatee = self;
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.moneyAry.count; i++) {
        [muAry addObject:self.moneyAry[i]];
    }
    [self.workExpsingSelected btnClickAddressWithData:muAry];
}
//选择工作经验
- (void)clickWorkExp{
    self.booltig = NO;
    self.workExpsingSelected = [SingleSelectedDialog sharedSelectedAddress];
    self.workExpsingSelected.delegatee = self;
    NSMutableArray *muAry = [NSMutableArray array];
    for (int i=0; i<self.workExpAry.count; i++) {
        [muAry addObject:self.workExpAry[i]];
    }
    [self.workExpsingSelected btnClickAddressWithData:muAry];
}
- (void)seceltedRow:(NSInteger)rrow{
    if (self.booltig) {
        [self updateResume:@"期望薪资" tigString:self.moneyAry[rrow]];
    }else
        [self updateResume:@"工作经验" tigString:self.workExpAry[rrow]]; 
}
//监听教育／职业经验变化
- (void)notiExperienceExp:(NSNotification *)noti{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    if ([dic[@"result"] integerValue] == 1){
        [self startNetWork];
    }
}


#pragma mark - 点击下一步
- (void)btnClickRight{
    LookResume *lookR = [[LookResume alloc] init];
    lookR.dicData = self.dicData;
    lookR.jobId = self.jobId;
    lookR.userid = self.userid;
    [self.navigationController pushViewController:lookR animated:YES];
}
//返回
- (void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 5;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {//求职信息
        return 3;
    }else if (section == 1){//技能标签
        return 1;
    }else if (section == 2) {
        return [self.dicData[@"work"] count];
    }else if (section == 3){
        return [self.dicData[@"education"] count];
    }else
        return 2;
 
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (indexPath.section == 0) {//求职信息
        if (indexPath.row == 0) {
            cell.textLabel.text = @"期望薪资";
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
            if ([self.dicData[@"paymentRange"] isEqualToString:@""]||[self.dicData[@"paymentRange"] isEqualToString:@"null"]) {
                cell.detailTextLabel.text = @"必填";
            }else
                cell.detailTextLabel.text = self.dicData[@"paymentRange"];
        }else if (indexPath.row == 1){
            cell.textLabel.text = @"行业方向";
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
            if ([self.dicData[@"industry"] isEqualToString:@""] || [self.dicData[@"industry"] isEqualToString:@"null"]) {
                cell.detailTextLabel.text = @"必填";
            }else
                cell.detailTextLabel.text = self.dicData[@"industry"];
        }else {
            cell.textLabel.text = @"工作经验";
            cell.textLabel.font = [UIFont systemFontOfSize:14];
            cell.detailTextLabel.font = [UIFont systemFontOfSize:14];
            if ([self.dicData[@"experience"] isEqualToString:@""] || [self.dicData[@"experience"] isEqualToString:@"null"]) {
                cell.detailTextLabel.text = @"必填";
            }else
                cell.detailTextLabel.text = self.dicData[@"experience"];
        }
    }else if (indexPath.section == 1){ //技能标签
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        if ([self.dicData[@"skillLable"] isEqualToString:@""]||[self.dicData[@"skillLable"] isEqualToString:@"null"]) {
            cell.textLabel.text = @"点击填写标签";
        }else
            cell.textLabel.text = self.dicData[@"skillLable"];
    }else if (indexPath.section == 2) {//工作经历
        NSArray *workAry = self.dicData[@"work"];
        cell.textLabel.text = workAry[indexPath.row][@"workName"];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.detailTextLabel.text = workAry[indexPath.row][@"workTime"];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else if (indexPath.section == 3){//教育经历
        NSArray *educationAry = self.dicData[@"education"];
        cell.textLabel.text = educationAry[indexPath.row][@"schoolName"];
        cell.textLabel.font = [UIFont systemFontOfSize:14];
        cell.detailTextLabel.text = educationAry[indexPath.row][@"schoolTime"];
        cell.detailTextLabel.font = [UIFont systemFontOfSize:10];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }else {//联系方式
        if (indexPath.row == 0) {
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, cell.width-2, cell.height)];
            label.font = [UIFont systemFontOfSize:14];
            if ([self.dicData[@"mobile"] isEqualToString:@""] || [self.dicData[@"mobile"] isEqualToString:@"null"]) {
                label.text = @"必填";
            }else{
                label.text = self.dicData[@"mobile"];
            }
            [cell addSubview:label];
            cell.textLabel.text = @"手机";
        }else{
            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(70, 0, cell.width-2, cell.height)];
            label.font = [UIFont systemFontOfSize:14];
            if ([self.dicData[@"email"] isEqualToString:@""] || [self.dicData[@"email"] isEqualToString:@"null"]) {
                label.text = @"必填";
            }else{
                label.text = self.dicData[@"email"];
            }
            [cell addSubview:label];
            cell.textLabel.text = @"邮箱";
        }
    }
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //取消选中状态
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    if (indexPath.section == 0) {//求职信息
        if (indexPath.row == 0) {//薪资
            [self clickMoney];
        }else if (indexPath.row == 1){//行业方向
            AreasConcern *areasConcernVC = [[AreasConcern alloc] init];
            areasConcernVC.titleString = @"行业方向";
            [self.navigationController pushViewController:areasConcernVC animated:YES];
        }else{//工作经验
            [self clickWorkExp];
        }
    }else if (indexPath.section == 1){//技能标签
        LabelVC *labelVC = [[LabelVC alloc] init];
        labelVC.titleString = @"技能标签";
        labelVC.hobbyArr = [NSMutableArray arrayWithArray:[self.dicData[@"skillLable"] componentsSeparatedByString:@","]] ;
        [self.navigationController pushViewController:labelVC animated:YES];
    }else if (indexPath.section == 2) {//工作经历
        ExperienceVC *experVC = [[ExperienceVC alloc] init];
        experVC.oldExperienceDic = self.dicData[@"work"][indexPath.row];
        experVC.tigStr = @"1";
        [self.navigationController pushViewController:experVC animated:YES];
    }else if (indexPath.section == 3){//教育经历
        ExperienceVC *experVC = [[ExperienceVC alloc] init];
        experVC.oldExperienceDic = self.dicData[@"education"][indexPath.row];
        experVC.tigStr = @"2";
        [self.navigationController pushViewController:experVC animated:YES];
    }else{//联系方式
        if (indexPath.row == 0) {
            [self title:@"联系电话" placeholedr:@"请输入您的联系电话" key:@"mobile" type:9];
        }else{
            [self title:@"邮箱地址" placeholedr:@"请输入您的邮箱" key:@"email" type:10];
        }
        
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
        return 20;
   
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    if (section == 2 || section == 3) {
        return 50;
    } else
        return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = RGB(247, 247, 247);
    
    if (section == 0) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 150, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = RGB(23, 176, 216);
        label.text = @"求职信息（必填）";
        [view addSubview:label];
        return view;
    }else if (section == 1){
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 150, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = RGB(23, 176, 216);
        label.text = @"技能标签（必填）";
        [view addSubview:label];
        return view;
    }else if (section == 2) {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 150, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = RGB(23, 176, 216);
        label.text = @"职业经历（必填）";
        [view addSubview:label];
        return view;
    }else if(section == 3){
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 150, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = RGB(23, 176, 216);
        label.text = @"教育经历（必填）";
        [view addSubview:label];
        return view;
    }else {
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, 150, 20)];
        label.font = [UIFont systemFontOfSize:14];
        label.textColor = RGB(23, 176, 216);
        label.text = @"联系方式";
        [view addSubview:label];
        return view;
    }
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    view.backgroundColor = [UIColor whiteColor];
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 8)];
    lineView.backgroundColor = RGB(247, 247, 247);
    [view addSubview:lineView];
    if (section == 2) {
        
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 8, self.view.width, 42)];
        [button setImage:[UIImage imageNamed:@"tianjia-anniu"] forState:UIControlStateNormal];
        [button setTitle:@"添加职业经历" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitleColor:RGB(117, 117, 117) forState:UIControlStateNormal];
        [button addTarget:self action:@selector(goWorkVC) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        return view;
    }else if (section == 3){
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 8, self.view.width, 42)];
        [button setImage:[UIImage imageNamed:@"tianjia-anniu"] forState:UIControlStateNormal];
        [button setTitle:@"添加教育经历" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14];
        [button setTitleColor:RGB(117, 117, 117) forState:UIControlStateNormal];
        [button addTarget:self action:@selector(goEducationVC) forControlEvents:UIControlEventTouchUpInside];
        [view addSubview:button];
        return view;
    }else
        return nil;
}


//那些行可编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0 || indexPath.section == 1) {
        return YES;
    }else
        return NO;
}

//编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleDelete;
}

//执行编辑样式的方法调用
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    [self startDeleteWithId:indexPath];
}
//添加职业经历
- (void)goWorkVC{
    ExperienceVC *experVC = [[ExperienceVC alloc] init];
    experVC.tigStr = @"3";
    [self.navigationController pushViewController:experVC animated:YES];
}
//添加教育经历
- (void)goEducationVC{
    ExperienceVC *experVC = [[ExperienceVC alloc] init];
    experVC.tigStr = @"4";
    [self.navigationController pushViewController:experVC animated:YES];
}


//去掉多余的表格线
- (void)setExtraCellLineHidden:(UITableView *)tableView{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    [tableView setTableFooterView:view];
}
//解决表格线不到左边界
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}

- (void)viewDidLayoutSubviews{
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
}




#pragma mark - 请求数据
- (void)startNetWork{
    [self showRoundProgressWithTitle:@"请稍后..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    muDicParameters[@"userType"] = [USER_DEFAULTS objectForKey:@"usertype"];
    muDicParameters[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
    muDicParameters[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
    
    [LSHttpTool sendHttpData:@"MyBasicMessage_app_myHome.im.lensum" params:muDicParameters success:^(id responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        if ([dicInfo[@"result"] integerValue] == 1) {
            self.dicData = dicInfo[@"data"];
            [self.tableView reloadData];
            
        }
        [self hideBubble];
        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}
#pragma mark - 删除数据
- (void)startDeleteWithId:(NSIndexPath *)indexPath{

    [self showRoundProgressWithTitle:@"请稍后..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    muDicParameters[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
    muDicParameters[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
    NSString *strURL = @"";
    if (indexPath.section == 0) { //工作
        strURL = @"deletePeopleWork_app_myHome.im.lensum";
        muDicParameters[@"workName"] = self.dicData[@"work"][indexPath.row][@"workName"];
    }else{
        strURL = @"deletePeopleEducation_app_myHome.im.lensum";
        muDicParameters[@"schoolName"] = self.dicData[@"education"][indexPath.row][@"schoolName"];
    }
    [LSHttpTool sendHttpData:strURL params:muDicParameters success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            [self startNetWork];
            [self hideBubble];
            ;
        }

    } failure:^(NSError *error) {

        [self showSingleIconBubble:error.localizedDescription];

    }];
}


#pragma mark - 求职信息／技能标签
- (void)updateResume:(NSString *)nsString tigString:(NSString *)titleString{
    //.修改简历http://localhost:8080/lensum/updateResume_app_jobhunting.im.lensum?token=XF2YkxodEFLmVot6svnA&userId=3237&paymentRange=期望薪资&industry=行业（多个英文逗号隔开）&skillLable=技能标签（多个英文逗号隔开）&experience＝工作经验

    [self showRoundProgressWithTitle:@"请稍等..."];
    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
    muDicParameters[@"userId"] = [USER_DEFAULTS objectForKey:@"userid"];
    muDicParameters[@"token"] = [USER_DEFAULTS objectForKey:@"token"];
    NSString *strUrl = @"updateResume_app_jobhunting.im.lensum";
    if ([nsString isEqualToString:@"期望薪资"]) {
        muDicParameters[@"paymentRange"] = titleString;
    }else if ([nsString isEqualToString:@"行业方向"]){
        muDicParameters[@"industry"] = titleString;
    }else if ([nsString isEqualToString:@"工作经验"]){
        muDicParameters[@"experience"] = titleString;
    }else if ([nsString isEqualToString:@"技能标签"]){
        muDicParameters[@"skillLable"] = titleString;
    }
    [LSHttpTool sendHttpData:strUrl params:muDicParameters success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];

        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            [self startNetWork];
            [self hideBubble];
            
        }else

        [self showSingleIconBubble:dicInfo[@"msg"]];

    } failure:^(NSError *error) {

        [self showSingleIconBubble:error.localizedDescription];
        
    }];
}


#pragma mark - 更改电话／邮箱
- (void)title:(NSString *)title placeholedr:(NSString *)placeholedr key:(NSString *)key type:(NSInteger)type{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField *nameField = [alert textFieldAtIndex:0];
    nameField.placeholder = placeholedr;
    if ([title isEqualToString:@"联系电话"]) {
        nameField.keyboardType = UIKeyboardTypePhonePad;
    }
    [alert showAlertWithCompletionHandler:^(NSInteger buttonIndex) {
        if(buttonIndex == 1){
            UITextField *tf=[alert textFieldAtIndex:0];
            if (tf.text.length > 0) {
                
                if ([title isEqualToString:@"邮箱地址"]) {
                    if (tf.text.length > 0 && [self isValidateEmail:tf.text] == YES) {
                        //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
                        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                        [muDicParameters setObject:tf.text forKey:key];//资源类型
                        
                        
                        [self startEditeUserInfoWithDic:muDicParameters withType:type];
                        
                    }else{

                        [self showSingleIconBubble:@"邮箱格式不正确"];
                        
                    }
                }else if([title isEqualToString:@"联系电话"]){
                    if (tf.text.length == 11) {
                        
                        NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                        [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                        [muDicParameters setObject:tf.text forKey:key];//资源类型
                        
                        [self startEditeUserInfoWithDic:muDicParameters withType:type];
                    }else{

                        [self showSingleIconBubble:@"手机号码格式不正确"];
                        
                    }
                }else{
                    //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
                    NSMutableDictionary *muDicParameters = [NSMutableDictionary dictionary];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"userid"] forKey:@"userId"];
                    [muDicParameters setObject:[USER_DEFAULTS objectForKey:@"token"] forKey:@"token"];//验证用户
                    [muDicParameters setObject:tf.text forKey:key];//资源类型
                    
                    [self startEditeUserInfoWithDic:muDicParameters withType:type];
                }
            }
        }
 
    }];
}
- (void)startEditeUserInfoWithDic:(NSDictionary *)dicc withType:(NSInteger)type
{
    //token=验证用户&userId=用户id&userName=修改用户名&sex=性别&age=年龄&positionName=职位&shipUserId=上属用户id&shipUserType=上属用户类别&address=地址&mobile=联系电话
    
    [self showRoundProgressWithTitle:@"请稍等..."];
    
    NSString *strURl = [NSString stringWithFormat:@"%@%@",URL_DEFINE,@"updateUser_People_app_myHome.im.lensum"];
        
 
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager POST:strURl parameters:dicc progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];

        //        NSLog(@"%@",dicInfo);
        if ([[dicInfo objectForKey:@"result"] integerValue] == 1) {
            
            [self startNetWork];
            [self hideBubble];
            
        }else {

            [self showSingleIconBubble:[dicInfo objectForKey:@"msg"]];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        [self showErrorWithTitle:@"1" autoCloseTime:2];
        
    }];
}

//判断邮箱格式
- (BOOL)isValidateEmail:(NSString *)email{
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}

@end
